package com.cennavi.mineplay.metadata;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

@RestController
@RequestMapping(value = "/studio")
public class StudioController {

	private static final Logger logger = LoggerFactory.getLogger(StudioController.class);
	
	
	@Autowired
	protected JdbcTemplate jdbc;

//	@RequestMapping("/basemap-list")
//	public List<ModelComp> basemapList(String name){
//		
//		try {
//			return basemapComp.basemapList(name);
//		} catch (FileNotFoundException e) {
//			logger.error(e.getMessage());
//			e.printStackTrace();
//		}
//		
//		return new ArrayList<>();
//		
//	}
	
	
	@RequestMapping("/basemap-list")
//	public List<ModelComp> basemapList(String name){
	public Object basemapList(String name){	
		 

			String sql = "select id,name,imageUrl,token from basemap_list";
			
			List<Map<String,Object>> list = jdbc.queryForList(sql);
			
			JSONArray ja = new JSONArray();
			
			for(Map<String,Object> m:list){
				JSONObject jo = new JSONObject();
				jo.put("id", m.get("id"));
				jo.put("imageUrl", m.get("imageUrl"));
				jo.put("name", m.get("name"));
				jo.put("token", m.get("token"));
				ja.add(jo);
			}
			
			return ja;
			
		 
		 
	}
	
	
	
	@RequestMapping("/basemap-default")
//	public List<ModelComp> basemapList(String name){
	public  Object defaultBaseMap(){	
		 

			String sql = "select id,name,imageUrl,token from basemap_list where picked=1";
			Map<String,Object> m = jdbc.queryForMap(sql);
			JSONObject jo = new JSONObject();
			jo.put("id", m.get("id"));
			jo.put("imageUrl", m.get("imageUrl"));
			jo.put("name", m.get("name"));
			jo.put("token", m.get("token"));
			
			return jo;
			
		 
		 
	}
	
	

	
	@RequestMapping("/release")
	public Object release(String content){
		
		
		return null;
	}
}
